﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.TM
{
    public partial class SM_RoleEdit : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["RoleID"] != null)
                {
                    DataTable dt = ZLDC.DAL.T_s_pdmDAL.GetRoleList(" where id=" + Request["RoleID"].Trim());
                    txtRoleDsc.Value = dt.Rows[0]["dsc"].ToString().Trim();
                    txtRoleName.Value = dt.Rows[0]["Name"].ToString().Trim();
                    txtRoleCode.Value = dt.Rows[0]["RoleCode"].ToString().Trim();
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("SM_RoleList.aspx");
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Request["RoleID"] != null)
            {
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.UpdateRole(txtRoleName.Value.Trim(), txtRoleDsc.Value.Trim(), txtRoleCode.Value.Trim(), Request["RoleID"].Trim());
            }
            else
            {
                DataTable dt = ZLDC.DAL.T_s_pdmDAL.GetRoleList(" where id=1");
                string pdm = dt.Rows[0]["pdm"].ToString().Replace('1', '0');
                ZLDC.Topo.BLL.Estate.T_s_pdmBLL.InsertRole(txtRoleName.Value.Trim(), txtRoleDsc.Value.Trim(), txtRoleCode.Value.Trim(), pdm);
            }
            Response.Redirect("SM_RoleList.aspx");
        }
    }
}
